<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/28 0028
 * Time: 20:55
 */

namespace app\storage\service;
use app\storage\Model\FeedModel;
use app\storage\Model\FeedDetailModel;
use service\excel\ExcelReaderFactory;
class FeedService
{
    private $feedModel;
    private $feedDetailModel;
    public function __construct()
    {
        $this->feedModel = new FeedModel();
        $this->feedDetailModel = new FeedDetailModel();
    }

    /***
     * @return mixed
     * 根据excel增加料站表信息
     */
    public function addByExcel()
    {
        $feed = ExcelReaderFactory::read('feed_seat');
        //实例化 service\excel\\feed\feedSeat.php文件。下面用到的checkExcelConfig()方法，checkData()方法，insertToDb()方法都写在这个文件中。

        $checkExcel = $feed->checkExcelConfig();//检查excel上传的配置
        if ($checkExcel['success'] === false) {
            return $checkExcel;
        }
        $checkData = $feed->checkData();//利用函数获取excel数据，同时检查数据是否有问题。
        if ($checkData['success'] === false) {
            return $checkData;
        }
        $result = $feed->insertToDb();//将读取的数据插入数据库中
        return $result;
    }
}